/** * * 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) */ /* * Prolog Code Generator */ using System; using System.Collections.Generic; using System.Text; using TUG.Mogentes.Codegen; namespace TUG.Mogentes.Codegen.Prolog { public sealed class OoaPrologIdentifier : OoaIdentifierVisitor { public class Factory { public OoaPrologIdentifier create() { return new OoaPrologIdentifier(); } } OoaCodeEmitter m_emitter; private void AddTokenText(Identifier anId) { m_emitter.Append(anId.tokenText); } public override void visit(EnumIdentifier enumIdentifier) { System.Diagnostics.Debug.Assert(false); // handled in visit(IdentifierExpression identifierExpression) //AddTokenText(enumIdentifier); } public override void visit(LandmarkIdentifier landmarkIdentifier) { AddTokenText(landmarkIdentifier); } public override void visit(AttributeIdentifier attributeIdentifier) { m_emitter.Append(String.Format("attr_{0}", attributeIdentifier.tokenText)); } public override void visit(ExpressionVariableIdentifier expressionVariableIdentifier) { m_emitter.Append(String.Format("ExprVar_{0}", expressionVariableIdentifier)); } public override void visit(ParameterIdentifier parameterIdentifier) { //m_emitter.Append(parameterIdentifier.tokenText.ToUpper()); if (parameterIdentifier.tokenText.Equals("result")) m_emitter.Append("RESULT"); else m_emitter.Append(String.Format("_{0}", parameterIdentifier.tokenText)); } public override void visit(LocalVariableIdentifier localVariableIdentifier) { m_emitter.Append(String.Format("_{0}", localVariableIdentifier.tokenText)); } public override void visit(TypeIdentifier typeIdentifier) { switch (typeIdentifier.type.kind) { case TypeKind.Any: // not supported case TypeKind.Null: // must have some type throw new NotImplementedException(); case TypeKind.OpaqueType: // must be resolved at this point in time case TypeKind.FunctionType: // we do not support declaration of function types System.Diagnostics.Debug.Assert(false); throw new NotImplementedException(); case TypeKind.FloatType: FloatType afloat = (FloatType)typeIdentifier.type; m_emitter.Append(String.Format("float_{0}_{1}_{2}", afloat.low, afloat.high, afloat.precision)); break; case TypeKind.IntType: IntType intType = (IntType)typeIdentifier.type; m_emitter.Append(String.Format("{0}", intType.identifier.tokenText.ToLower())); break; case TypeKind.BoolType: m_emitter.Append("bool"); break; case TypeKind.EnumeratedType: m_emitter.Append(String.Format("enum_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix)); break; case TypeKind.TupleType: m_emitter.Append(String.Format("tuple_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix)); break; case TypeKind.ListType: m_emitter.Append(String.Format("list_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix)); break; case TypeKind.QrType: case TypeKind.MapType: throw new NotImplementedException(); case TypeKind.OoActionSystemType: m_emitter.Append(String.Format("'{0}'", typeIdentifier.tokenText)); //AddTokenText(typeIdentifier); break; default: throw new NotImplementedException(); } } public override void visit(MethodIdentifier methodIdentifier) { m_emitter.Append(String.Format("'{0}'", methodIdentifier.tokenText)); } public override void visit(NamedActionIdentifier namedActionIdentifier) { m_emitter.Append(String.Format("'{0}'", namedActionIdentifier.tokenText)); } public override string ToString() { return m_emitter.ToString(); } private OoaPrologIdentifier() { m_emitter = new OoaCodeEmitter(); } } }