Commit 9198cda4 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

* fix for blocks, assignment, variable use, identifiers, and reserved keywords, &27

parent 1e728d2c
Loading
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import org.etsi.mts.tdl.TimeOut;
import org.etsi.mts.tdl.TimerStart;
import org.etsi.mts.tdl.TimerStop;
import org.etsi.mts.tdl.UnboundedLoopBehaviour;
import org.etsi.mts.tdl.VariableUse;
import org.etsi.mts.tdl.VerdictAssignment;

import java.util.List;
@@ -61,7 +62,7 @@ import org.etsi.mts.tdl.OmitValue;

public class TTCN3Renderer {
	private List<String> binaryFunctions = List.of("+", "-", "*", "/", "mod", "or", "and", "xor", "!=", "<", ">", "<=", ">=", "==");
	private List<String> keywords = List.of("message", "port", "value", "length");
	private List<String> keywords = List.of("message", "port", "value", "length", "type", "trigger", "self");
	private String indent = "  ";
	private String LF = "\n";
	
@@ -71,6 +72,9 @@ public class TTCN3Renderer {
		if (keywords.contains(cleanName)) {
			cleanName+="_";
		}
		if (cleanName.startsWith("_")) {
			cleanName="N"+cleanName;
		}
		return cleanName;
	}
	
@@ -83,7 +87,7 @@ public class TTCN3Renderer {
			output+=indent+this.indent+"import from "+ttcnName(i.getImportedPackage())+" all;"+LF;
		}
		output+=indent+this.indent+"modulepar float mp_componentElapsedTimerMaxDuration;"+LF;
		//TODO: outsource in a library?
		//TODO: outsource in a library? -> leads to duplications all over
		output+=indent+this.indent+"type charstring SimpleDataType;"+LF;
		output+=indent+this.indent+"type charstring String;"+LF;
		output+=indent+this.indent+"type integer Integer;"+LF;
@@ -262,6 +266,7 @@ public class TTCN3Renderer {
			case OmitValue u -> "omit";
			case CastDataUse u -> render(u, indent);
			case PredefinedFunctionCall u -> render(u, indent);
			case VariableUse u -> render(u, indent);
			default -> renderUnsupported(e, indent);
		}
		;
@@ -343,6 +348,12 @@ public class TTCN3Renderer {
		return output;
	}

	String render(VariableUse e, String indent) {
		String output = "";
		output += ttcnName(e.getVariable());
		return output;
	}
	
	String render(PredefinedFunctionCall e, String indent) {
		String output = "";
		String function = e.getFunction().getName();
@@ -540,12 +551,14 @@ public class TTCN3Renderer {
			for (var g : e.getBlock().getGuard()) {
				if (g.getComponentInstance() == c) {
					guard+="if ("+render(g.getExpression(), "")+") ";
				}
			}
		}
					output+=indent+guard+"{"+LF;
					output+=render(e.getBlock(), indent+this.indent, c);
					output+=indent+"}"+LF;
				}
			}
		} else {
			output+=render(e.getBlock(), indent+this.indent, c);
		}
		return output;
	}

@@ -662,7 +675,7 @@ public class TTCN3Renderer {
			case Stop u -> indent+"mtc.stop"+LF;
			case VerdictAssignment u -> indent+"setverdict("+render(u.getVerdict(), "")+")"+LF;
			case Assertion u -> render(u, indent, c);
			case Assignment u -> render(u, indent, c);
			case Assignment u -> render(u, indent);
			case ActionReference u -> render(u, indent, c);
			case InlineAction u -> render(u, indent, c);
			default -> renderUnsupported(e, indent);