@@ -22,6 +22,7 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
2222 private val classifiesTable: MutableMap <String , Pair <String , String >> = mutableMapOf ()
2323 private val checkClassifiesTable: MutableMap <String , MutableMap <String , Pair <String , String >>> = mutableMapOf ()
2424 private val contextTable : MutableMap <String , String > = mutableMapOf ()
25+ private val streamersTable : MutableMap <String , MutableMap <String , MutableSet <Expression >>> = mutableMapOf ()
2526
2627 private fun translateModels (ctx : Models_blockContext ) : Pair <List <Pair <Expression , String >>, String>{
2728 if (ctx is Simple_models_blockContext )
@@ -75,6 +76,11 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
7576 addClassifyQuery(cl.className.text, cl.classifies_block(), null )
7677 }
7778 }
79+
80+ // create streamer configuration
81+ if (cl.streamer != null ) {
82+ streamersTable[cl.className.text] = mutableMapOf ()
83+ }
7884 val inFields = if (cl.external != null ) {
7985 var res = listOf<FieldInfo >()
8086 if (cl.external.fieldDecl() != null ) {
@@ -141,6 +147,14 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
141147 val params = if (nm.paramList() != null ) paramListTranslate(nm.paramList()) else listOf ()
142148 res[nm.NAME ().text] = MethodInfo (SkipStmt (ctx!! .start.line), params, nm.builtinrule != null , nm.domainrule != null , cl.className.text, metType)
143149 }
150+ if (nm.emits_block() != null ) {
151+ if (! streamersTable.containsKey(cl.className.text))
152+ throw Exception (" Class with methods containing emits clause must be a streamer: ${nm.NAME ().text} " )
153+
154+ streamersTable[cl.className.text]!! [nm.NAME ().text] = mutableSetOf ()
155+ for (i in 0 until nm.emits_block().expression().size)
156+ streamersTable[cl.className.text]!! [nm.NAME ().text]!! + = visit(nm.emits_block().expression(i)) as Expression
157+ }
144158 }
145159 table[cl.className.text] = Pair (fields, res)
146160 }
@@ -179,7 +193,7 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
179193
180194 return Pair (
181195 StackEntry (visit(ctx.statement()) as Statement , mutableMapOf (), Names .getObjName(" _Entry_" ), Names .getStackId()),
182- StaticTable (fieldTable, methodTable, hierarchy, modelsTable, hidden, owldescr, checkClassifiesTable, contextTable)
196+ StaticTable (fieldTable, methodTable, hierarchy, modelsTable, hidden, owldescr, checkClassifiesTable, contextTable, streamersTable )
183197 )
184198 }
185199
@@ -402,6 +416,35 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
402416 return SimulationStmt (target, path, res, ctx!! .start.line, declares)
403417 }
404418
419+ override fun visitMonitor_statement (ctx : Monitor_statementContext ? ): ProgramElement {
420+ val target = visit(ctx!! .target) as Location
421+ if (ctx.declType != null ) {
422+ val decl = getClassDecl(ctx)
423+ val className = if (decl == null ) ERRORTYPE .name else decl!! .className.text
424+ val targetType = TypeChecker .translateType(ctx.declType, className, mutableMapOf ())
425+ target.setType(targetType)
426+ }
427+
428+ val query = visit(ctx!! .registeredQuery) as Expression
429+ val ll = emptyList<Expression >().toMutableList()
430+ for (i in 2 until ctx!! .expression().size)
431+ ll + = visit(ctx.expression(i)) as Expression
432+
433+ return MonitorStmt (target, query, ll, ctx!! .start.line, target.getType())
434+ }
435+
436+ override fun visitWindow_statement (ctx : Window_statementContext ? ): ProgramElement {
437+ val target = visit(ctx!! .target) as Location
438+ if (ctx.declType != null ) {
439+ val decl = getClassDecl(ctx)
440+ val className = if (decl == null ) ERRORTYPE .name else decl!! .className.text
441+ val targetType = TypeChecker .translateType(ctx.declType, className, mutableMapOf ())
442+ target.setType(targetType)
443+ }
444+ val monitor = visit(ctx!! .monitor) as Expression
445+ return WindowStmt (target, monitor, ctx!! .start.line, declares= target.getType())
446+ }
447+
405448 override fun visitTick_statement (ctx : Tick_statementContext ? ): ProgramElement {
406449 return TickStmt (visit(ctx!! .fmu) as Expression , visit(ctx!! .time) as Expression )
407450 }
@@ -418,7 +461,8 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
418461 val def = getClassDecl(ctx as RuleContext )
419462 val declares = if (ctx!! .declType == null ) null else
420463 TypeChecker .translateType(ctx.declType, if (def != null ) def!! .className.text else ERRORTYPE .name, mutableMapOf ())
421- return AssignStmt (visit(ctx!! .expression(0 )) as Location , visit(ctx.expression(1 )) as Expression , ctx!! .start.line, declares)
464+ val isClock = if (ctx.clock == null ) false else true
465+ return AssignStmt (visit(ctx!! .expression(0 )) as Location , visit(ctx.expression(1 )) as Expression , isClock, ctx!! .start.line, declares)
422466 }
423467
424468 override fun visitSkip_statment (ctx : Skip_statmentContext ? ): ProgramElement {
0 commit comments