Project

General

Profile

root / branches / compiler / cSharp / ooasCompiler / src / codegen / Prolog / ooaPrologIdentifier.cs

1
/**
2
  *
3
  *                      OOAS Compiler (Deprecated)
4
  *
5
  * Copyright 2015, Institute for Software Technology, Graz University of
6
  * Technology. Portions are copyright 2015 by the AIT Austrian Institute
7
  * of Technology. All rights reserved.
8
  *
9
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
10
  *
11
  * Please notice that this version of the OOAS compiler is considered de-
12
  * precated. Only the Java version is maintained.
13
  *
14
  * Contributors:
15
  *               Willibald Krenn (TU Graz/AIT)
16
  *               Stefan Tiran (TU Graz/AIT)
17
  */
18

    
19
/*
20
 * Prolog Code Generator
21
 */
22

    
23
using System;
24
using System.Collections.Generic;
25
using System.Text;
26
using TUG.Mogentes.Codegen;
27

    
28

    
29
namespace TUG.Mogentes.Codegen.Prolog
30
{
31
    public sealed class OoaPrologIdentifier : OoaIdentifierVisitor
32
    {
33
        public class Factory
34
        {
35
            public OoaPrologIdentifier create() { return new OoaPrologIdentifier(); }
36
        }
37

    
38

    
39
        OoaCodeEmitter m_emitter;
40

    
41
        private void AddTokenText(Identifier anId)
42
        {
43
            m_emitter.Append(anId.tokenText);
44
        }
45

    
46

    
47
        public override void visit(EnumIdentifier enumIdentifier)
48
        {
49
            System.Diagnostics.Debug.Assert(false); // handled in visit(IdentifierExpression identifierExpression)
50
            //AddTokenText(enumIdentifier);
51
        }
52

    
53
        public override void visit(LandmarkIdentifier landmarkIdentifier)
54
        {
55
            AddTokenText(landmarkIdentifier);
56
        }
57

    
58
        public override void visit(AttributeIdentifier attributeIdentifier)
59
        {
60
            m_emitter.Append(String.Format("attr_{0}", attributeIdentifier.tokenText));
61
        }
62

    
63
        public override void visit(ExpressionVariableIdentifier expressionVariableIdentifier)
64
        {
65
            m_emitter.Append(String.Format("ExprVar_{0}", expressionVariableIdentifier));
66
        }
67

    
68
        public override void visit(ParameterIdentifier parameterIdentifier)
69
        {
70
            //m_emitter.Append(parameterIdentifier.tokenText.ToUpper());
71
            if (parameterIdentifier.tokenText.Equals("result"))
72
                m_emitter.Append("RESULT");
73
            else
74
                m_emitter.Append(String.Format("_{0}", parameterIdentifier.tokenText));
75
        }
76

    
77
        public override void visit(LocalVariableIdentifier localVariableIdentifier)
78
        {
79
            m_emitter.Append(String.Format("_{0}", localVariableIdentifier.tokenText));
80
        }
81

    
82
        public override void visit(TypeIdentifier typeIdentifier)
83
        {
84
            switch (typeIdentifier.type.kind)
85
            {
86
                case TypeKind.Any:          // not supported
87
                case TypeKind.Null:         // must have some type
88
                    throw new NotImplementedException();
89

    
90
                case TypeKind.OpaqueType:   // must be resolved at this point in time
91
                case TypeKind.FunctionType: // we do not support declaration of function types
92
                    System.Diagnostics.Debug.Assert(false);
93
                    throw new NotImplementedException();
94

    
95
                case TypeKind.FloatType:
96
                    FloatType afloat = (FloatType)typeIdentifier.type;
97
                    m_emitter.Append(String.Format("float_{0}_{1}_{2}", afloat.low, afloat.high, afloat.precision));
98
                    break;
99
                case TypeKind.IntType:
100
                    IntType intType = (IntType)typeIdentifier.type;
101
                    m_emitter.Append(String.Format("{0}", intType.identifier.tokenText.ToLower()));
102
                    break;
103

    
104
                case TypeKind.BoolType:
105
                    m_emitter.Append("bool");
106
                    break;
107

    
108
                case TypeKind.EnumeratedType:
109
                    m_emitter.Append(String.Format("enum_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix));
110
                    break;
111

    
112
                case TypeKind.TupleType:
113
                    m_emitter.Append(String.Format("tuple_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix));
114
                    break;
115

    
116
                case TypeKind.ListType:
117
                    m_emitter.Append(String.Format("list_{1}{0}", typeIdentifier.tokenText, typeIdentifier.prefix));
118
                    break;
119

    
120
                case TypeKind.QrType:
121
                case TypeKind.MapType:
122
                    throw new NotImplementedException();
123

    
124
                case TypeKind.OoActionSystemType:
125
                    m_emitter.Append(String.Format("'{0}'", typeIdentifier.tokenText));
126
                    //AddTokenText(typeIdentifier);
127
                    break;
128

    
129
                default:
130
                    throw new NotImplementedException();
131
            }
132

    
133
        }
134

    
135
        public override void visit(MethodIdentifier methodIdentifier)
136
        {
137
            m_emitter.Append(String.Format("'{0}'", methodIdentifier.tokenText));
138
        }
139

    
140
        public override void visit(NamedActionIdentifier namedActionIdentifier)
141
        {
142
            m_emitter.Append(String.Format("'{0}'", namedActionIdentifier.tokenText));
143
        }
144

    
145

    
146
        public override string ToString()
147
        {
148
            return m_emitter.ToString();
149
        }
150

    
151
        private OoaPrologIdentifier()
152
        {
153
            m_emitter = new OoaCodeEmitter();
154
        }
155
    }
156
}