Commit 66cd13dd authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ ttcn3 mapping improvements and fixes

parent 086cfd05
......@@ -31,6 +31,17 @@ operation String size() : Integer {
//Supporting operations
operation Any getPackage() : Any {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(TDL!Package)) {
return self.eContainer.getPackage();
} else {
return self.eContainer;
}
}
}
operation Any getTestDescription() : Any {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(TDL!TestDescription)) {
......
......@@ -27,7 +27,16 @@ operation Any TTCNname() : String {
if (qualifiedNaming) {
ttcnName = self.qualifiedName();
}
if (packagePrefix) {
if (self.getPackage().isDefined()) {
ttcnName = self.getPackage().name+"_"+ttcnName;
}
}
ttcnName = ttcnName.replace("::","_");
ttcnName = ttcnName.replace("\\.","_");
ttcnName = ttcnName.replace("\\^","");
ttcnName = ttcnName.replace("value","value_");
ttcnName = ttcnName.replace("^(\\d)","d$1");
if (ttcnName = "integer"
or ttcnName = "charstring"
or ttcnName = "float") {
......
......@@ -4,7 +4,9 @@ import "helper.eol";
import "debug.eol";
pre {
("Transforming..").log(1);
var modelFile = new Native("java.io.File") (TDL.getModelImpl().getURI().toString().replaceAll("^file:",""));
("Transforming : " +modelFile.getName()).log(1);
//TODO:export configuration
//use data mapping
......@@ -24,18 +26,20 @@ pre {
//generate age timers
var generateAgeTimers = true;
//add package prefix
//(until naming in multi-package / multi-module naming is resolved)
var packagePrefix = false;
var predefined = new Set();
predefined.add("String");
predefined.add("Integer");
predefined.add("Boolean");
predefined.add("Verdict");
var mpElapsedTime;
var f = new TTCN!TTCN3File();
var stack = new Map();
var currentScope;
}
post {
......@@ -59,7 +63,7 @@ rule Package2Module
//TODO: to support annotations and comments for elements
// need to add contained comments as a feature
// in module definitions
(" "+p.name).log(1);
(" Package: "+p.name).log(1);
m.name = p.TTCNname();
f.modules.add(m);
if (p.packagedElement.notEmpty() or p.`import`.notEmpty()) {
......@@ -76,9 +80,12 @@ rule Package2Module
var mp = new TTCN!ModuleParameter;
mp.name = "mp_componentElapsedTimerMaxDuration";
if (packagePrefix) {
mp.name = p.name+"_"+mp.name;
}
md.def.param.list.params.add(mp);
mpElapsedTime = mp;
m.~mpElapsedTime = mp;
m.defs.definitions.add(md);
}
......@@ -88,6 +95,9 @@ rule Package2Module
rule ElementImport2ImportDef
transform ei : TDL!ElementImport
to i : TTCN!ImportDef {
guard : ei.importedPackage.equivalent().isDefined()
("Import from: "+ei.importedPackage.name).log(1);
i.name = ei.importedPackage.equivalent().name;
//i.name = "mappings";
......@@ -624,8 +634,10 @@ rule CT2C
ti.expr = new TTCN!Value();
ti.expr.ref = new TTCN!ReferencedValue();
ti.expr.ref.head = new TTCN!Head;
ti.expr.ref.head.target = mpElapsedTime;
(" Module: "+c.getModule()).log(1);
(" Timer: "+c.getElapsedTime()).log(1);
ti.expr.ref.head.target = c.getElapsedTime();
var d = new TTCN!ComponentDefList();
c.defs.add(d);
......@@ -758,7 +770,10 @@ rule SimpleDI2TD
transform di : TDL!SimpleDataInstance
to td : TTCN!TemplateDef {
//guard : false
guard : not useDataMapping and not di.isValue() and di.dataType.name <> "Verdict"
guard : not useDataMapping
and not di.isValue()
and di.dataType.name <> "Verdict"
and di.dataType.name <> "Boolean"
var md = new TTCN!ModuleDefinition();
md.def = td;
......@@ -825,7 +840,7 @@ rule StructuredDI2TD
td.body = tb;
if ((di.unassignedMember.isDefined()
and not di.dataType.member.forAll(m|
and not di.dataType.allMembers().forAll(m|
di.memberAssignment.exists(ma|ma.member = m)))
//does it need to be recursive?
or di.memberAssignment.exists(ma|
......@@ -966,6 +981,27 @@ rule CollectionDI2C
}
operation Any getModule() : TTCN!TTCN3Module {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(TTCN!TTCN3Module)) {
return self.eContainer.getModule();
} else {
return self.eContainer;
}
}
}
operation Any getElapsedTime() : Any {
var mpElapsedTime = self.getModule().getElapsedTime();
return mpElapsedTime;
}
operation TTCN!TTCN3Module getElapsedTime() : Any {
var mpElapsedTime = self.~mpElapsedTime;
return mpElapsedTime;
}
operation TTCN!TTCN3Module createTypeDefBody() : TTCN!TypeDefBody{
var md = new TTCN!ModuleDefinition();
md.def = new TTCN!TypeDef();
......@@ -1040,38 +1076,58 @@ operation Any transformSingleMemberAssignment(m : TDL!Member, mad : TDL!DataUse)
} else {
//nested anonymous definitions
//or overriding
body.field = mad.transformWildcardMemberAssignment();
}
} else {
body.simple = new TTCN!SimpleSpec();
body.simple.spec = new TTCN!SimpleTemplateSpec();
body.simple.spec.expr = new TTCN!SingleTemplateExpression();
body.simple.spec.expr.symbol = new TTCN!MatchingSymbol();
if (mad.isUndefined()
and self.unassignedMember.isDefined()
and self.unassignedMember.name = "AnyValueOrOmit") {
if (m.isOptional) {
body.simple.spec.expr.symbol.anyornone = "*";
(" : "+mad.item).log(1);
if (mad.item.isDefined()) {
body = self.transformDefaultMatchingSymbol(m, mad);
} else {
body.simple.spec.expr.symbol.any = "?";
body.field = mad.transformWildcardMemberAssignment();
}
} else if (mad.isUndefined()
and self.unassignedMember.isDefined()
and self.unassignedMember.name = "AnyValue") {
body.simple.spec.expr.symbol.any = "?";
} else if (mad.isDefined()
and mad.isKindOf(TDL!AnyValue)) {
body.simple.spec.expr.symbol.any = "?";
} else if (mad.isDefined()
and mad.isKindOf(TDL!AnyValueOrOmit)) {
body.simple.spec.expr.symbol.anyornone = "*";
} else if (mad.isDefined()) {
("TODO: Implement?").log(1);
}
}
} else {
body = self.transformDefaultMatchingSymbol(m, mad);
}
return body;
}
operation Any transformDefaultMatchingSymbol(m : TDL!Member, mad : TDL!DataUse) : TTCN!TemplateBody {
var body = new TTCN!TemplateBody();
body.simple = new TTCN!SimpleSpec();
if (mad.isUndefined()
or not mad.isKindOf(TDL!LiteralValueUse)) {
body.simple.spec = new TTCN!SimpleTemplateSpec();
body.simple.spec.expr = new TTCN!SingleTemplateExpression();
body.simple.spec.expr.symbol = new TTCN!MatchingSymbol();
}
if (mad.isUndefined()
and self.unassignedMember.isDefined()
and self.unassignedMember.name = "AnyValueOrOmit") {
if (m.isOptional) {
body.simple.spec.expr.symbol.anyornone = "*";
} else {
body.simple.spec.expr.symbol.any = "?";
}
} else if (mad.isUndefined()
and self.unassignedMember.isDefined()
and self.unassignedMember.name = "AnyValue") {
body.simple.spec.expr.symbol.any = "?";
} else if (mad.isDefined()
and mad.isKindOf(TDL!AnyValue)) {
body.simple.spec.expr.symbol.any = "?";
} else if (mad.isDefined()
and mad.isKindOf(TDL!AnyValueOrOmit)) {
body.simple.spec.expr.symbol.anyornone = "*";
} else if (mad.isDefined()
and mad.isKindOf(TDL!LiteralValueUse)) {
//("TODO: Implement full support for literal values : "+mad).log(1);
body.simple.expr = new TTCN!Value();
body.simple.expr.predef = new TTCN!PredefinedValue();
body.simple.expr.predef.charString = mad.value;
} else if (mad.isDefined()) {
("TODO: Implement? : "+mad).log(1);
}
return body;
}
operation TDL!StaticDataUse transformWildcardMemberAssignment() : TTCN!FieldSpecList {
//dataInstance? or inferred type
//unassignedMember?
......@@ -1091,37 +1147,45 @@ operation TDL!StaticDataUse transformWildcardMemberAssignment() : TTCN!FieldSpec
("TODO: Context Not Implemented Yet").log(1);
}
}
for (m in t.member) {
if (self.item.isDefined() or t.isKindOf(TDL!CcollectionDataType)) {
("TODO: Collections not supported yet: "+self).log(1);
(" "+t.name).log(1);
var it = t.itemType;
var fs = new TTCN!FieldSpec();
fs.ref = m.equivalent();
var mad;
var ma = self.argument.selectOne(a|a.parameter = m);
//default: no wildcard, defined
//in case not defined, check for inherited
if (ma.isDefined()) {
mad = ma.dataUse;
} else if (ma.isUndefined()
and self.isKindOf(TDL!DataInstanceUse)
and self.dataInstance.isDefined()) {
var mai = self.dataInstance.memberAssignment.selectOne(a|a.member = m);
if (mai.isDefined()) {
mad = mai.memberSpec;
}
} else {
}
fs.body = self.transformSingleMemberAssignment(m, mad);
field.spec.add(fs);
}
} else {
for (m in t.allMembers()) {
var fs = new TTCN!FieldSpec();
fs.ref = m.equivalent();
var mad;
var ma = self.argument.selectOne(a|a.parameter = m);
//default: no wildcard, defined
//in case not defined, check for inherited
if (ma.isDefined()) {
mad = ma.dataUse;
} else if (ma.isUndefined()
and self.isKindOf(TDL!DataInstanceUse)
and self.dataInstance.isDefined()) {
var mai = self.dataInstance.memberAssignment.selectOne(a|a.member = m);
if (mai.isDefined()) {
mad = mai.memberSpec;
}
} else {
}
fs.body = self.transformSingleMemberAssignment(m, mad);
field.spec.add(fs);
}
}
return field;
}
operation TDL!StructuredDataInstance transformWildcardMemberAssignment() : TTCN!FieldSpecList {
var field = new TTCN!FieldSpecList();
for (m in self.dataType.member) {
for (m in self.dataType.allMembers()) {
var fs = new TTCN!FieldSpec();
fs.ref = m.equivalent();
......@@ -1175,7 +1239,7 @@ operation TDL!StructuredDataInstance transformMemberAssignment() : TTCN!Compound
//TODO: handle unassigned members? -> add guards to corresponding rule
//TODO: handle special characters
var assigned = self.memberAssignment.collect(ma|ma.member);
for (m in self.dataType.member.excludingAll(assigned)) {
for (m in self.dataType.allMembers().excludingAll(assigned)) {
(self.name + ": Skipping unassigned member "+m.name).log(1);
}
......@@ -1226,7 +1290,7 @@ operation TDL!DataType getTTCNType() : TTCN!Type {
operation TTCN!TTCN3Module getSDT() : TTCN!SubTypeDefNamed {
if (self.~sdt.isUndefined()) {
var sdt = new TTCN!SubTypeDefNamed();
sdt.name = "SimpleDataType";
sdt.name = self.name+"_SimpleDataType";
sdt.type = new TTCN!Type();
//TODO: make configurable?
sdt.type.`pre` = "charstring";
......@@ -1336,9 +1400,17 @@ operation TDL!DataInstanceUse getTemplateBody() : TTCN!TemplateBody {
tb.simple.expr.predef.charString = "MAP_"+self.dataInstance.name;
}
} else {
tb.simple.expr.ref = new TTCN!ReferencedValue();
tb.simple.expr.ref.head = new TTCN!Head();
tb.simple.expr.ref.head.target = self.dataInstance.equivalent().base;
if (self.dataInstance.isDefined()) {
tb.simple.expr.ref = new TTCN!ReferencedValue();
tb.simple.expr.ref.head = new TTCN!Head();
tb.simple.expr.ref.head.target = self.dataInstance.equivalent().base;
} else if (self.dataType.isDefined()) {
("Not supported yet: "+self).log(1);
} else if (self.item.isDefined()) {
("Not supported yet: "+self).log(1);
} else {
("Not supported yet: "+self).log(1);
}
}
return tb;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment