use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_BitString_Type method check.
@Override
public /**
* {@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 == namedValues) {
parseBlockBitstring();
}
if (isErroneous || null == namedValues) {
return;
}
/* check named bits */
final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final Identifier identifier = namedValue.getName();
if (nameMap.containsKey(identifier.getName())) {
final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
nameMap.put(identifier.getName(), identifier);
}
}
final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final IValue value = namedValue.getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
continue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
{
final Integer_Value integerValue = (Integer_Value) last;
if (integerValue.isNative()) {
final int intValue = integerValue.intValue();
final Integer intValueObject = Integer.valueOf(intValue);
if (intValue < 0) {
value.getLocation().reportSemanticError(MessageFormat.format("A non-negative INTEGER value was expected for named bit `{0}'' instead of {1}", namedValue.getName().getDisplayName(), intValueObject));
value.setIsErroneous(true);
continue;
}
if (valueMap.containsKey(intValueObject)) {
value.getLocation().reportSemanticError(MessageFormat.format("Duplicate value {0} for named bit `{1}''", intValueObject, namedValue.getName().getDisplayName()));
value.setIsErroneous(true);
final NamedValue temp = valueMap.get(intValueObject);
temp.getLocation().reportSemanticError(MessageFormat.format("Bit {0} is already assigned to name `{1}''", intValueObject, temp.getName().getDisplayName()));
} else {
valueMap.put(intValueObject, namedValue);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value `{0}'' is too big to be used as a named bit", integerValue.getValueValue()));
value.setIsErroneous(true);
}
break;
}
default:
namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named bit `{0}''", namedValue.getName().getDisplayName()));
break;
}
}
nameMap.clear();
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method generateCode.
/**
* Add generated java code on this level.
* @param aData only used to update imports if needed
* @param source the source code generated
*/
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String ownName = getGenNameOwn();
final String displayName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<EnumItem> items = new ArrayList<EnumItem>();
if (enumerations != null) {
if (enumerations.enumItems1 != null) {
items.addAll(enumerations.enumItems1.getItems());
}
if (enumerations.enumItems2 != null) {
items.addAll(enumerations.enumItems2.getItems());
}
}
final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
final ArrayList<Enum_field> fields = new ArrayList<EnumeratedGenerator.Enum_field>(items.size());
for (int i = 0; i < items.size(); i++) {
final EnumItem tempItem = items.get(i);
fields.add(new Enum_field(tempItem.getId().getName(), tempItem.getId().getDisplayName(), ((Integer_Value) tempItem.getValue()).getValue()));
}
final Enum_Defs e_defs = new Enum_Defs(fields, ownName, displayName, getGenNameTemplate(aData, source, myScope), hasRaw);
EnumeratedGenerator.generateValueClass(aData, source, e_defs);
EnumeratedGenerator.generateTemplateClass(aData, source, e_defs);
generateCodeForCodingHandlers(aData, source);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value 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.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeAssignmentStatement.
// updated
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
// TODO assignments for indexed bitstrings
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
/*StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Integer_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Charstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Boolean_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN("
+ functionAssignValues.get(assignCounter) + ");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Referenced_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if ((specValTemplate.getSpecificValue() instanceof AddExpression)
|| (specValTemplate.getSpecificValue() instanceof SubstractExpression)
|| (specValTemplate.getSpecificValue() instanceof MultiplyExpression)
|| (specValTemplate.getSpecificValue() instanceof DivideExpression)
|| (specValTemplate.getSpecificValue() instanceof ModuloExpression)
|| (specValTemplate.getSpecificValue() instanceof RemainderExpression)) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter)
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
}
*/
return functionString.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Testcase_Writer method writeAssignmentStatement.
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder testCaseString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate.getSpecificValue();
createCounter++;
logCreateCounter++;
int logSizeValue = 1;
while (tcCreateCounter.get(logCreateCounter).equals(String.valueOf(createCounter))) {
logCreateCounter++;
logSizeValue++;
if (tcCreateCounter.size() == (logCreateCounter)) {
break;
}
}
String[] logValues = new String[logSizeValue];
int logWriteCounter = 0;
testCaseString.append("rownum=" + componenetCreateExp.getLocation().getLine() + ";\r\n");
if (tcAssignIdentifiers.get(assignCounter).endsWith("=")) {
tcAssignIdentifiers.set(assignCounter, tcAssignIdentifiers.get(assignCounter).substring(0, tcAssignIdentifiers.get(assignCounter).length() - 1));
}
testCaseString.append("hc.create(" + "\"" + tcAssignIdentifiers.get(assignCounter) + "\"");
logValues[logWriteCounter] = tcAssignIdentifiers.get(assignCounter);
currentCounterValue++;
// assignCounter++;
logWriteCounter++;
while (tcCreateCounter.get(currentCounterValue).equals(String.valueOf(createCounter))) {
testCaseString.append(",\"" + tcCreateValues.get(currentCounterValue) + "\"");
logValues[logWriteCounter] = tcCreateValues.get(currentCounterValue);
logWriteCounter++;
currentCounterValue++;
if (tcCreateCounter.size() == (currentCounterValue)) {
break;
}
}
testCaseString.append("); " + "\r\n");
testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + nodeName + "\", \"Starting PTC " + logValues[0] + " type " + logValues[1] + " on " + logValues[2] + "\", false);" + "\r\n");
} else if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
// TODO assignments for indexed bitstrings
testCaseString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
testCaseString.append(tcAssignIdentifiers.get(assignCounter) + tcAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
return testCaseString.toString();
}
Aggregations