/** * * 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; using TUG.Mogentes.Codegen.Prolog; namespace TUG.Mogentes.Codegen.PrologSymbolic { public class OoaPrologSymbolicStatement : OoaPrologStatement { public new class Factory : OoaPrologStatement.Factory { public override OoaPrologStatement create( OoaPrologExpression.Factory exprFactory, OoaPrologIdentifier.Factory idFactory, OoaPrologType.Factory typeFactory) { return new OoaPrologSymbolicStatement(exprFactory, idFactory, typeFactory); } } public override void visit(Assignment assignment) { if (assignment.nondetExpression != null) throw new NotImplementedException(); LinkedListNode aPlace = assignment.places.First; LinkedListNode aValue = assignment.values.First; List assignments = new List(); while (aPlace != null) { OoaPrologExpression prologPlace = createExpressionVisitor(true); aPlace.Value.Accept(prologPlace); System.Diagnostics.Debug.Assert(prologPlace.tmpVariables.Count == 1); OoaPrologExpression prologValue = createExpressionVisitor(); aValue.Value.Accept(prologValue); System.Diagnostics.Debug.Assert(prologValue.tmpVariables.Count == 1); m_emitter.Append(prologValue.ToString()); if (aPlace.Value.kind == ExpressionKind.Access && ((AccessExpression)aPlace.Value).right.kind == ExpressionKind.Identifier && ((IdentifierExpression)((AccessExpression)aPlace.Value).right).identifier.kind == IdentifierKind.AttributeIdentifier) { //access to attribute is always 'self.XY'... assignments.Add(String.Format("{0} := {1}", prologPlace.tmpVariables[0], prologValue.tmpVariables[0])); } else if (prologPlace.tmpVariables[0] == "RESULT") assignments.Add(String.Format("unify( RESULT = {0})", prologValue.tmpVariables[0])); // else if (aPlace.Value.type.kind == TypeKind.IntType) // assignments.Add(String.Format("{0} #= {1}", prologPlace.tmpVariables[0], prologValue.tmpVariables[0])); else assignments.Add(String.Format("{0} = {1}", prologPlace.tmpVariables[0], prologValue.tmpVariables[0])); if (prologPlace.ToString().Length > 0) { string place = prologPlace.ToString(); place = place.Trim(); if (place.EndsWith(",")) place = place.Substring(0, place.Length - 1); assignments.Add(place); } aPlace = aPlace.Next; aValue = aValue.Next; } int pos = 0; foreach (var s in assignments) { if (pos != 0) m_emitter.Append(","); pos++; m_emitter.Append(s); } } public override void visit(SeqBlock seqBlock) { int y = 0; if (seqBlock.symbols.symbolList.Count > 0) { m_emitter.Append(" ["); foreach (Identifier sym in seqBlock.symbols.symbolList) { if (y != 0) m_emitter.AppendLine(", "); else y++; OoaPrologType atype = createTypeVisitor(); sym.type.Accept(atype); OoaPrologIdentifier anIdent = createIdentifierVisitor(); sym.Accept(anIdent); m_emitter.Append(String.Format("{0}:{1}", anIdent.ToString(), atype.ToString())); } m_emitter.Append("]: ( "); } y = 0; foreach (Statement x in seqBlock.statements) { if (y != 0) m_emitter.AppendLine(", "); else y++; m_emitter.Append("("); VisitSub(x, seqBlock); m_emitter.Append(")"); } if (seqBlock.symbols.symbolList.Count > 0) m_emitter.Append(")"); } protected OoaPrologSymbolicStatement( OoaPrologExpression.Factory exprFactory, OoaPrologIdentifier.Factory idFactory, OoaPrologType.Factory typeFactory) : base(exprFactory, idFactory, typeFactory) { } } }