/** * * OOAS Compiler (Deprecated) * * Copyright 2015, Institute for Software Technology, Graz University of * Technology. Portions are copyright 2015 by the AIT Austrian Institute * of Technology. All rights reserved. * * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED. * * Please notice that this version of the OOAS compiler is considered de- * precated. Only the Java version is maintained. * * Contributors: * Willibald Krenn (TU Graz/AIT) * Stefan Tiran (TU Graz/AIT) */ using System; using System.Collections.Generic; using System.Text; namespace TUG.Mogentes { /// /// removes trivial prioritized compositions. /// public sealed class OoaRemoveTrivialPrioritizedCompositionVisitor : OoaCompleteAstTraversalVisitor { /// /// replaces the prioBlock by its child (most likely a parBlock) /// private IAst ConvertPrioBlock(PrioBlock prioBlock, IAst parent) { if (prioBlock.statements.Count <= 1) { LinkedListNode child = prioBlock.statements.First; Block newBlock = (Block)child.Value; switch (parent.nodeType) { case AstNodeTypeEnum.type: switch (((UlyssesType)parent).kind) { case TypeKind.OoActionSystemType: OoActionSystemType atype = (OoActionSystemType)parent; Block ablock = atype.doOdBlock; System.Diagnostics.Debug.Assert(ReferenceEquals(ablock, prioBlock)); atype.SetDoOdBlock(newBlock); break; default: throw new NotImplementedException(); } break; case AstNodeTypeEnum.statement: switch (((Statement)parent).kind) { case StatementKind.SeqBlock: SeqBlock aseqblock = (SeqBlock)parent; LinkedListNode toChange = aseqblock.statements.Find(prioBlock); toChange.Value = newBlock; break; case StatementKind.GuardedCommand: GuardedCommand gc = (GuardedCommand)parent; System.Diagnostics.Debug.Assert(ReferenceEquals(gc.body, prioBlock)); gc.SetBody(newBlock); break; default: throw new NotImplementedException(); } break; case AstNodeTypeEnum.identifier: switch (((Identifier)parent).kind) { case IdentifierKind.MethodIdentifier: MethodIdentifier method = (MethodIdentifier)parent; System.Diagnostics.Debug.Assert(ReferenceEquals(method.body, prioBlock)); method.SetBody(newBlock); break; default: throw new NotImplementedException(); } break; default: throw new NotImplementedException(); } return newBlock; } else return prioBlock; } protected override void VisitAstElement(IAst element, IAst parent) { if ((element.nodeType == AstNodeTypeEnum.statement) && (((Statement)element).kind == StatementKind.PrioBlock) && // we're only interested in actionblock and actionbody composition, not in type composition !(parent.nodeType == AstNodeTypeEnum.identifier && ((Identifier)parent).kind == IdentifierKind.List)) { IAst newchild = ConvertPrioBlock((PrioBlock)element, parent); base.VisitAstElement(newchild, parent); } else base.VisitAstElement(element, parent); } public override void visit(MainModule mainModule) { // get rid of any top-level spurious block if (mainModule.systemDescription != null) while (mainModule.systemDescription.identifiers.Count == 1 && mainModule.systemDescription.identifiers.First.Value.kind == IdentifierKind.List) { mainModule.SetSystemDescription((IdentifierList)mainModule.systemDescription.identifiers.First.Value); } base.visit(mainModule); } public OoaRemoveTrivialPrioritizedCompositionVisitor(ParserState aState) : base(aState) { } } }